
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>ajax请求 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="vuex.html" />
    
    
    <link rel="prev" href="api.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="directory.html">
            
                <a href="directory.html">
            
                    
                    目录规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="api.html">
            
                <a href="api.html">
            
                    
                    API规范
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4" data-path="ajax.html">
            
                <a href="ajax.html">
            
                    
                    ajax请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="vuex.html">
            
                <a href="vuex.html">
            
                    
                    VUEX规范
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >ajax请求</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="ajax&#x8BF7;&#x6C42;">ajax&#x8BF7;&#x6C42;</h1>
<p>&#x6280;&#x672F;&#x9009;&#x578B;&#xFF1A;<code>axios.js</code><br><a href="https://github.com/axios/axios" target="_blank">https://github.com/axios/axios</a></p>
<p>&#x672C;&#x793A;&#x4F8B;&#x9879;&#x76EE;&#x5DF2;&#x7ECF;&#x5728;&#x5168;&#x5C40;&#x914D;&#x7F6E;&#x597D;&#x4E86;&#x57FA;&#x7840;&#x7684;&#x914D;&#x7F6E;&#xFF0C;&#x5E76;&#x63D0;&#x4F9B;&#x4E86;&#x5982;&#x4F55;&#x914D;&#x7F6E;&#x57FA;&#x7840;&#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#x7684;&#x6700;&#x4F73;&#x5B9E;&#x8DF5;&#x3002;</p>
<h3 id="&#x914D;&#x7F6E;&#x8BF7;&#x6C42;&#x6839;&#x8DEF;&#x5F84;">&#x914D;&#x7F6E;&#x8BF7;&#x6C42;&#x6839;&#x8DEF;&#x5F84;</h3>
<p>&#x5728;&#x4E1A;&#x52A1;&#x6A21;&#x5757;&#x4E2D;&#x7684;public/config.js&#x4E2D;&#xFF0C;&#x914D;&#x7F6E;baseURL&#x5373;&#x53EF;</p>
<pre><code class="lang-js">! <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">e, t</span>) </span>{
  <span class="hljs-string">&quot;object&quot;</span> == <span class="hljs-keyword">typeof</span> exports ? exports.appConfig = t(e) : e.appConfig = t(e)
}(<span class="hljs-string">&quot;undefined&quot;</span> != <span class="hljs-keyword">typeof</span> self ? self : <span class="hljs-keyword">this</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">e</span>) </span>{
  <span class="hljs-keyword">let</span> config = {
    debug: <span class="hljs-literal">false</span>,
    baseURL: <span class="hljs-string">&apos;http://localhost:8080/base&apos;</span>,
  }
  <span class="hljs-keyword">return</span> config
})
</code></pre>
<h3 id="&#x5177;&#x4F53;&#x4F7F;&#x7528;">&#x5177;&#x4F53;&#x4F7F;&#x7528;</h3>
<p>&#x5728;&#x4E1A;&#x52A1;&#x5F00;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5168;&#x5C40;&#x4F7F;&#x7528;</p>
<pre><code class="lang-js"><span class="hljs-keyword">this</span>.$http.get(<span class="hljs-string">&apos;url&apos;</span>, {
  params: {
    key1: <span class="hljs-string">&apos;val1&apos;</span>
  }
}).then(r=&gt;{
  <span class="hljs-comment">//do something</span>
})

<span class="hljs-keyword">this</span>.$http.post(<span class="hljs-string">&apos;url&apos;</span>, {
  key1: <span class="hljs-string">&apos;val1&apos;</span>
}).then(r=&gt;{
  <span class="hljs-comment">//do something</span>
})
</code></pre>
<h4 id="&#x7F13;&#x5B58;&#x8BF7;&#x6C42;">&#x7F13;&#x5B58;&#x8BF7;&#x6C42;</h4>
<p>&#x4E00;&#x822C;&#x7528;&#x4E8E;&#x8BF7;&#x6C42;&#x4E00;&#x4E9B;&#x6BD4;&#x8F83;&#x56FA;&#x5B9A;&#x7684;&#x4E0B;&#x62C9;&#x9009;&#x9879;&#xFF0C;&#x6216;&#x5B57;&#x5178;&#x9879;&#x7B49;&#x60C5;&#x51B5;&#x4E0B;&#x4F7F;&#x7528;</p>
<p>&#x6BD4;&#x6B63;&#x5E38;&#x7684;&#x8BF7;&#x6C42;&#x591A;&#x4E86;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7528;&#x4E8E;&#x914D;&#x7F6E;&#x7F13;&#x5B58;&#x8FC7;&#x671F;&#x65F6;&#x95F4;&#xFF0C;&#x5355;&#x4F4D;&#xFF1A;ms</p>
<pre><code class="lang-js"><span class="hljs-keyword">this</span>.$http.getByCache(<span class="hljs-string">&apos;url&apos;</span>, {
  key1: <span class="hljs-string">&apos;val1&apos;</span>
},{ time: <span class="hljs-number">60</span>*<span class="hljs-number">1000</span> }).then(r=&gt;{
  <span class="hljs-comment">//do something</span>
})
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="api.html" class="navigation navigation-prev " aria-label="Previous page: API规范">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="vuex.html" class="navigation navigation-next " aria-label="Next page: VUEX规范">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ajax请求","level":"1.4","depth":1,"next":{"title":"VUEX规范","level":"1.5","depth":1,"path":"vuex.md","ref":"vuex.md","articles":[]},"previous":{"title":"API规范","level":"1.3","depth":1,"path":"api.md","ref":"api.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"ajax.md","mtime":"2020-03-17T13:06:10.476Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-19T06:12:42.684Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

